fix bugs and improve doc