1. graceful termination on xnix. 2. cleaned up the code a bit