refactored logic into a controller

and wired up adding images