drafts of main algorithm and need functions