log and error handler refactored