Code optimizations + cleanup