further work on query planning