Move some code from view to model where it belongs