Refactoring to include a much better caching mechanism