documentation and some bug fixing