Big performance imporovement

Scrapped the permutation thing and just did some tree traversal