More careful null checking and member initalization.
Merge remote-tracking branch 'upstream/master'

Merge with upstream