Updated Final Code