Refactor: got rid of outside switch statement using inheritance.

In process of gettting rid of inside switch statements also.