working state replay. Need cleanup