Fixed bug where only first instance was being replaced.