fix bugs and add debug info