rewrite - better use of objects, but breaks api - improve tests and add test coverage