Bug fixes to mappings and query