Refactored some code to allow one script to use another