Adapted SPADE algorithm to not use so much memory and no crash. But it needs optimization.