refactor using classes