complete the main logic