Refactor the (while []) loops to use while-let which is cleaner.