Added comments, refactored caching