Fixed loop errors