Fix potential null pointer exception