fixed tests and refactored model logic