Serious refactoring to more OO solution to reduce conditional noise and ensure extensibility.