add correctness check
actually get algorithm right