refactoring: encapsulated functions to classes.