Refactored to accomodate major CachedInputStream changes.