some fixes for potential nil crashes