Refactored some code.
Fixed traversing of the history and demo history initialization.