Fix file operation bugs