did most things, there is still some weird recursion and conditionals to be rid of.