Change place of query function