Refactored all methods dealing with selection to use common logic in addSelection() and removeSelection() and avoided triggering events when no changes occurred.