Made template link logic simpler