first draft of algo