Modify functions to always generate a matrix