bug fixes optimizations