use objects, add tests, improve comments