moving logic out of template