Functional algorithms but pretty long