Merged in Adam's code