Refactor expiration calculation