Created boolean condition to check when the program ends
Rearranged IDstage