ditch recursion for faster generation
slight optimizations