separate string preprocessing into a separate function