Some clean ups and fixed unit tests.