refactor tests and push logic to models