refactored MVC of images.js file