refactor the program to OO style