Tried adding else to close file to prevent file descriptor leak