Some useful algorithms!