Refactoring to a class structure