refactoring the code for set operation