refactoring error code