fixing potential crashes