refactored and fixed tests to work