more error refactoring