unit tests, unit tests, unit tests!!

added unit tests, plus some general cleanup