Implemented history replay. Cleaning up code.