Refactor code into a class