Optimizing function that clean string