fix problems with javascript code not being loaded at the right time