Moved main JS function to external script called into index