Added code to guarantee exclusive database lock