Fixed some nullpointer exceptions