NPE and initialization bug fixes.