Refactored structure of JavaScript