Refactor image manager helpers
Fix image replacement bug