Fix terminal selection routine