misc speedups

just follow the commits one by one and they will be obvious to you.