Add the code & tests of phase2 and phase3