error refactoring, part 2 & minor cleanup