Added first draft of algorithm code.Z