output needs not to be a matrix but a dataframe.