patchwork/tools: refactor code.