Added image caching, fixed cache bugs.