Initial algorithm to code