fixes, optimizations and more