progress on fixing writeFile memory leak