main logic