added code for phase to have initial and final code states