improved error handler; refactoring; output