I implemented the query function