Improve debug mode and Fix some bugs.