reorganization and improvement for expiry calculations