Exception handling for file ops, also fixed a bug.