Fix expiration algorithm