Updated Javascript code