some fixes and write documentation