cleanup old while loop implementation