fix bugs and improve documentation