Updated origin template logic