Fix'd nullpointer exceptions