Removed the costly while loop