Added check to fix crashes on undefined instances

Jira issue: WP-1269
Merge pull request #58 from smonteleone/WP-1269

Added check to fix crashes on undefined instances