Pruning algorithm (still working on it)