Merged upstream main.c changes