tweaked some code layout; made exitThread check if main