Added a function to better query data.
Fixed a bug.