Various Algorithms and useful classes