DOM generation and vars optimisation