Furher refactored the design to use InstanceType class and moved some of
the logic inside.