Found a stupid bug in the query construction code.