Improved square matrix detection

The original implementation only checked the length of the first row. You may want to consider stronger assertions in your matrix methods in general.