Moves many $db ref's from controller into model [#713 milestone:2.2.2 responsible:dleffler]