Do some cppcheck-directed cleanup.

Tighten scopes for some variables, remove the unused adjust_panel(), remove
some other unused variables or assignments.