added null pointer handling