Refactoring the template functions' queries.