Fixing some perf bugs