COMP: Remove unused variables

There were several variables that were unused that were removed,
and in also variables that could have more narrow scope were placed
such that they are not always computed.  Finally, it is much better
to use const references when possible so that unnecessary copying
is not done.