Fixing code and unused variables