chan's algo now working