Move some initialization code to make it more similar to the code in main_mt.c
Remove unecessary goto statement.
Move code to separate IO specific stuff.