Use single transaction to acquire lock

Single transaction and updated tests