main function cleanup