Added mostly complete code.