Adding query support, and various bug fixes and code cleanup
added examples for querying datasets