Refactor the code to follow OO principles