Change some JavaScript by simplification and re-factoring.