refactor Giovanna code and put it in correct js file