First algorithm implementation