Made file I/O, exception handling more Pythonic