Moved template functions into models for easier reuse