implementations for various algorithms