Refactored some script variables and fixed some issues