New metaquery api

Currently a work in progress