Finish p-step memory. Refactor chapter 2.