finish main logic