Fix more bugs and compilation error