Fix 'for' off by one errors