add a proper null pointer check