add tests and general cleanup