Minor fixes for random selection code