Improve select deselect and lock logic