unit tests and cleanups