reduce global variables, move isntantiation to html file