cleanup and File-handling fixes for windows