fixed phase3, which had a small error (phase 3 has branching)