fix mistakes in order of ELSE in second function