refactor signal handling