cleanup, add tests

and generally get it working