optimizations and other fixes