Performance improvements & while loop