Refactoring to group the duplicates
Cleaning up the code