Fix signal handler for SIGINT

The loop now corretly exits when SIGINT is received.