Refactor signal trapping