Improved error/exception handler and logging