Fixing potential nil pointer error