Cleanups and some unittests