Refactored and fixed unit tests.