Updated Code. Tested.