Refactored code into utility class