refactored signal handler