fixing potential bad access crashes