porting segfault fix (in signal handling) from optimize branch
Merge branch 'master' into optimize