changed queries in line with latest pull request from Sandro