refactor code for listbox