Refactored to a more OO design