fixed main select loop