Define number_of_squares and replace i by square_index if relevant