refactoring and removing unused variables