Add unit test for clearExpiredTokens and fix expiration logic