added npe check in viewer