Updated some functions for matrix format