Simplified while loop as per code review feedback