Moving changes from toms branch in by hand.