Converted to use HashMap and clean the code.