Added check that file handle returned succesfully