Changed to vector[][][]

This is much easier to reason about and is less likely to cause rounding
or logical errors.