Added main documentation. Some bugfixes and cleanup.