Implemented caching and fixed bugs