Fix a bug that causes filehandle error