signal handler moved to a better place