clean up some refactored variables

Recent refactoring left several unused variables. The first four patches clean those up.

The fifth one is a real bug-fix which can cause a segfault.