Refactored selected element code into model