Balance HTML before calculation and insertion