Refactored cache invalidation a little bit
Cleaned up the formatting a bit