more image generation refactoring