slideshow code refactor