Updated file handling, removed extraneous close