added the runwithlock method