Multiple bugfixes; update documentation.