better for loop condition, small style changes