Simplify code for 2331b73

Remove unused variables and combine `var` statement.
Reference issue #3371.