Refactor error handler registering