fixed tests, refactored