589 lines of code later and 7 refactors, solution complete