Added debugging and caching.