Moved template logic to view