ground up rewrite. need more tests.