Fixed some NPEs and other misc. errors. Pretty much done.