Code optimizations

[x] Various code cleanups