refactoring error and context