Remove unnecessary while loop