final version of Andy's thesis