document the sql.compound_inverse_query method
properly close cursors
more refactoring
Merge branch 'refactor' into unstable