Adding phil budne's code. Thanks phil.