Refactor and clean up replay tool.