fixed writeFile method, and a few minor changes