lots of fixes and huge rewriting and documentation