implement deep readlink to eliminate repeating code