fix possible crashes