fix loop condition