Moved some methods that relate to the model.
Some minor fixes and refactoring.