refactor javascript organization