Finished main function