cleanup code
replace while by for loop