Added javascript and fixed update logic