Added tests, and some general cleanup