Better fix than previous: only performs the casting if the value is a string