Various bugfixes and work on the documentation