Fixed bug in selection function.