Whoops better close the files

Added file close functions to avoid the program hogging them forever
unnecessarily.