Improve error handling. Move code around in START-OUTPUT so that