refine lock & unlock logic