length zero division error fix

fix if length of a link equal zero to avoid zero devision error in the code.