Refactoring to EventHandler and ErrorHandler