fixing potential runtime errors