Change loops to remove .length()