refactor error