wrote methods for when query