Cleanup main function