reshuffle code around, and make tests a lot more readable