Added further tests and documentation. Minor bug fixes.