Fixed bugs with program flow.