Added check to fix crashes on undefined instances

Jira issue: WP-1269