taken some changes from other branches, blueprint for query