Fix possible null pointer exception