refactor code with a more oop approach