tons of changes and optimizations