add code for phase0 through phase3