Finishing main function