Optimizing the search for useless moves to lock