Fix bug with output module and add tests.