Remove unused variables and helper function