Added fix for potential nullpointerexception