Refactor, ditch while loop