Added calc_minrun() and fin_run() and reversing of descending runs