* write to temp file and move to state file * fixed memleak and other issues * call windows replace function with MOVEFILE_WRITE_THROUGH flag * moved few functions to platform package * moved test files to correct dir * addressed comments