major improvements and optimizations