log immediately before executing query, remove premature error return (was pointless and error-prone)
fix integration test, return last error but reset it immediately
Added close method
Merge remote branch 'upstream/master'