Simplified code for dealing with nxm arrays and added testing for that case.