Put string sanitising into a function, and handle exception whilst tuning