Substantially cleaned up sample code.