refactored a bit and added tests for the model