A bit more logging, plus fixes to the queries.