Fix a NPE which occurs when state is null