Fix bugs raised by Ganjin