optimize the structure of javascript