Implemented caching mechanism to speed things up.