Chain codes almost working