working on query function