Fix query schema, polish code style a bit.