More changes, tests, refactoring, comments, etc.