Fix to handle excessive trailing slashes. Most of this path-bending stuff should be done properly, not with drop and dropWhile and so on.