Make application loop reentrant. Cleanup app init code.