Move script execution into functions and set executable bits