Fixing errors

Template and query