Woring commit
Rewrite working to some degree, needs testing with different datasets