Add nextExc function. Reformat code