added protection against null pointers