passes all tests, just needs commenting and refining.