Made template queries more generic