Improve robustness of link utility functions

Fixes #321, fixes #323