refactoring, no need to do this calculation every time
adding test for all failures in reverse order
more tests, and test refactorings