refactor signal handler