implemented query next