Adding more javascript for faster polling and more responsive and flexible updating of states