Fix bugs and debug codes