Add debug information and fix some bugs.