first draft of algorithm