Refactor a bit, document, add some tests, clean up bad file
Add tests, add phase-detection logic, add TODO
Update Changes