Use case insesitive map and do a little code tidying and combining.