new error handler

Many fixes, including a proper error handler.