Modified the i and j for x and y directions