add debug, fix defects