Cleanup of main function