Only using authentication when 401 is encountered
Updated version