fixing bug in signal handler