Improving performance by tweaking expensive code