Final Updated code