Fix null ref exception. Fixes #148.