making more robust, and fixing logic for function returning a full pathname now.