Added an exists() method to RawHistory and refactored both of the functions to be smaller.  bug #4955.