Fix compiler warnings
Fix a bugs, add debug information