Updated code. Added Comments