algorithms2: some error refactoring