Added null check
Fixes #544