Moved some routines out of the model/controller