refactor to support array-like behavior for selected elements