Changed file open logic to be more 'pythonic' using 'with open', empty files still work correctly