Made while loop less intensive