Improve code for slideshow