Fix potential null pointer error