Fixes for building the query model