refactoring the code structure with OO style