Included before_query and after_query in template and updated check().