Modify functions to always generate a matrix
Refactor the disparate functions into one