JS code reorganize