Code refactor with replay functionality