refactor of changeImage method