Added double locking for opening db's