moved template logic