Script reorganized in functions