Make script even more modular

Continues #4754