Updated javascript code