Refactored and fixed tests.