refactored, fixed tests