Remove unused variables. Fix nesting bug.