Fixed error on undefined string replace()

Hey Martyn,
Fixed an error I ran into occasionally. Consider this my first contribution to someone else's code, ever! I'm not sure of etiquette but I'm sure this easily merged so I figured I'd give it a shot :)

Regards,
Wybe Minnebo, the Netherlands