refactoring of thumbnail JS and simple image viewer