Clean up unused variables. Fix a bug.