Turn all exits inside main into returns, replace exit(1) by exit(FAILURE).