fix error text handling and remove a lot of debug statements