You’re getting the error in line 33 because you’re invoking words.get(t), but you’re in the else block where words.containsKey(t) is false.
I think what you really want is not 2 maps w/ count, but 1 map of lowercase -> count and 1 map of lowercase -> first seen version of string.