fixed output to file taking too long