Refactor createImageElements in preparation for category switching.