Merged Adam's Code.

Merged Adam's Code.