Add multiple selections support (and some refactoring)