Reorganized code for calc example.