replace nitems with n, is an unsigned so maybe faster? probably not