merge phase transition code