I think it works now. Basically moved sig handler code to main loop.

I also commented out any calls to set up sig handler.