add unit tests, refactor model