Complete implementation of selection