Fixed nullpointer bugs.