Check for nil when getting state - fixes #8