improved caching and fixed some minor bugs