improved template finder