fix bug in language selection algorithm