Fix a null pointer exception bug