Tidy up selection code.