Fix various bugs in output tests and generate answer files