Refactor code to class