fix loop errors