file writing fixed