Checkbox code optimization