Bug fixes and performance optimizations