Refactoring the bejeezus out of it