faster solution for df and matrices, fixes #58