fixed 401 handling and made trailing slash optional.