Performance improvements

Some performance improvements.

The last commit needs some more work. Read commit text.