lots of code regarding image generation and caching