refactor a bit, add possibility to test the selection code