Added code for the heirarchical method.