Improved token refreshing with additional test cases