refectoring

remove if else
add while looping
update for debug code