Do some cppcheck-directed cleanup.

Tighten scopes for some variables, remove the unused adjust_panel(), remove
some other unused variables or assignments.
Merge pull request #315 from elly/cppcheck

Do some cppcheck-directed cleanup.