refactors javascript structure