Moved model logic outside of templates