Fixed and error with the loops