added checking for N² shape