Changed matrix types to immutable