cleanup and fixes so that sigaction works correctly