performance tuning on solution for problem 32