Fix query, and a bit cleanup.