Code for all 4 phases