refactored js organization