Improve code to use more OO inheritance