finished main logic