Updated function to select deselect entities