Extracted function for preprocessing into separate script