removing unused variables and duplicates