The write-your-own-recursion actually works! It looks horrid but I'll fix that