Chord aglorithm written by zly