move selected image logic into controller