Added null check to prevent nullpointer