Improved handling of trailing/starting slashes in paths