Several bugfixes related to output