completed first draft of algo 1