Fix some Null Pointer Exception in the code