Finally figured out logic for editting image