Loads of optimizations and some fine-tuning