fixing null ptr exception