cleaner more robust implementation for selection
cleaner structure
pahabol