fixing a bug null ptr