add null pointer protection