Refactor into different scripts