made sure to close the files in close()function