More optimization and revamping of JS code.