added checks for null pointers