more small bug fixes and added function to convert 2 dimensions of a 3d matrix into a 2d matrix