Finished main logic