Cleaned up a bit of code, and use pprint for the cache