Moved preprocessing functions out of the main script