main logic finished