be sure to mark javascript local variables with var
put new unique functions inside the primary function