removed redundant code at while-loops