Refactoring in choose_element.js