Total rewrite of ugly recursion.
Partially functional and I'm about to change some stuff