fixed NPE with dereferencing a pointer too many times