clean up main function