error refactor