Fixed output empty file bug