add the link length and clena the code and add some comments