Performance cleanups

Sorry... the performance changes of the last pull request are lost (first time that I use github; and I think I use it wrong ;)). I check the code again and add the performance improvements from the last pull request and found same more performance fixes and code cleanups.

A summery of the improvments are in the decription of the commits. If there are any questions, please comment the lines directly...