modified by wangliang for replay