Fix potential crashes