refactoring error sorting