An early refactor. Some ideas became clearer as development continued. Now the various phases are much clearer and more easily reusable. Also added a ton of tests! Change-Id: Ic8f0a70c8222370352e63533b329c40457c0903e
Change-Id: I307f56d9631784ab29ee4156d94886f9b2f25b30