Added a non-empty value condition prior to the replacement