Attempted to make it not use recursion






I also fixed some inefficiencies



unfortunately it didn't really work
committed by g-rocket