"big change in new loop function and next_real to make it rebust in extreme case"