Fixed some nil pointer errors.