added file operations, fixed some bugs