Better language detection

Closes #22, #40, and probably others