Fixing some loop condition