refactored caching.py. also easier on the eyes