Main Javascript code