Added a condition for the validity of program name before computing for the next level name.