Adding locing logic