Moving selectedItem calculation outside of the conditional.