Moved array-building from template to controller