Moved query impl into absctractdatasture.
Some general cleanup and refinements.