fix null pointer exception bugs