Fix potential NPE in class loading and add extra debug information.