improved loop condition