correct algorithm implementation