improves language detection, adds tests