Refactor the code using classes