[refactor] changed some while-loops to for-loops and removed all console.logs