fixed null exception. Fixes #309