Fixed several Null Pointer exceptions