Duh - reference counting is not thread-safe! And a few other fixes.
All test should pass and sqlite seems to working stably under heavy
loads.