Moved data generation logic into controller from view