Moving DB queries out of view into model

err… that's better!