Fixed a few uncommon NPE bugs.