Ensured the file is close on end - need tests though