Fixed bug in output.cpp where an invalidated iterator was iterated