More optimizations

This PR will grow with new commits. I'll push commits one by one to have CI run.
shape