Algorithm implementation