Fix recursion issue with submodpath function