- got rid of global variable and took advantage of dict.setdefault for
  caching