new way of locking, added api for batches; added option for auto-reconnecting