completed first draft of algorithm