fix possible null pointer exceptions