Refactor model and tests