Improved implementation of various matrix types