Added NULL checks and assertions for pointers of Graph elements.