Only call replace on string arguments

Prevents errors being thrown when trying to call replace on non-string
arguments.