more null checking, fixes #177 and fixes #172