LOADS of code optimizations (THANKS Ilya)