Made script slightly modular.