State variable not defined in some circumstances

Instagram, for example, is complaining. This change correctly checks the ```'state'``` variable.