Refactors lock behavior