Adresses #1526 - Moved some more code into model.