Undo last change. Found a better way to locate errors.
Bugfix: removed trailing slash on output_dir
Bugfix: check for metadata section count
Catch parse errors and write output to new working_dir until error-free.