refactor signal handling for cleanup functions