Enhanced text replacement - fixes #29