Refactoring to class based functions