Made script a bit more modular