refactor code to OO