finished implimenting query function