fix duplication bug with template

I also simplified it a little to make it clear!