Refactored and cleaned up external JS