add tests and do some general cleanup