Refactor initialisation JavaScript