fix possible null reference exceptions