Added NULL checks