Decent round of fixes, expecially nullpointers.