rewrote find_link_lengths to try and reduce ridiculous memory usage