made minors changes to JS including defining an undefined variable