properly handle signals