Optimisations

Please review to see if I did anything stupid. In my many test runs everything seemed to be fine.