Refactored into a class and methods