Improve corpus preprocessing code