Improved error handler, added comments