Branch

Many changes, fixes a couple of bugs.
See commit messages.