Some minor optimizations and profiling