Added fix for potential nullpointer exception