fixed some bugs with caching