recoded stop part with while loop