Rearanged some of the code to allow for better script importing