Photo Viewer; needs refactoring for duplicate code