Fixing potential null reference error