added query function. Needs a lot of work...