Added untested first pass at full code.