add guards to rebalance/replace
fix reset/finalize/unlock of several sql statements