bugs and optimizations