Refactored the corpus utilities.
bug fixes