problem fixes and optimizations