Changed NSInteger idx values to NSUInteger