Code refined and bug fixed.