Some fixes:

1. Close files after opening
2. Handle non-existent files gracefully
3. Fix a bug reading empty files