new fixes and optimizations