private static String toWords(int n) {
        final String s = String.valueOf(n);
        final int l = s.length();
        if (l == 1) {
            return numbersToWords.get(n);
        } else if (l == 2) {
            if (numbersToWords.containsKey(n)) {
                return numbersToWords.get(n);
            }
            final int tens = n / 10 * 10;
            final int ones = n - tens;
            return numbersToWords.get(tens) + " " + numbersToWords.get(ones);
        } else if (l == 3) {
            final int hundreds = n / 100 * 100;
            final int remainder = (n - hundreds);
            if (numbersToWords.containsKey(remainder)) {
                return numbersToWords.get((hundreds / 100)) + " hundred and " + numbersToWords.get(remainder);
            } else {
                final int tens = (n - hundreds) / 10 * 10;
                final int ones = n - hundreds - tens;
                if (ones > 0 && tens > 0) {
                    return numbersToWords.get((hundreds / 100)) + " hundred and " + numbersToWords.get(tens) + " " + numbersToWords.get(ones);
                } else if (tens > 0) {
                    return numbersToWords.get((hundreds / 100)) + " hundred and " + numbersToWords.get(tens);
                } else {
                    return numbersToWords.get((hundreds / 100)) + " hundred";
                }
            }
        } else if (l == 4) {
            final int thousands = n / 1000 * 1000;
            return numbersToWords.get((thousands / 1000)) + " thousand";
        }
        return null;
    }