improved error handler (still needs improvement, though)