moving logic out of the template