massive JS reorganization and clean-up