A little refactoring to avoid all the sprintf and too many string
comparaisons. Completely untested