Use type Dimension instead of int (be careful in the following lines however, since some loops may use the fact that i or j may become negative).