Check for nil when getting state - fixes #8

I forgot to add a check for nil in my previous pull request :(