a whole lot of refactorings and refined test cases