Fix bug in which changing checkboxes would result in bad sorting