refactor attacking code