replanning code