Major changes, inclusion of for loops, reduce script size