implemented the Viewer class and relevant helper functions