Error refactor