Some optimizations

Have a look if this works for you. It shouldn't break anything. ;)