I know that recursive functions are usually slower than loops, I just wrote a recursive function because it is easier to write, without having to handle a position-tracking stack.

By the way, I don't want to rewrite it now, I'm starting to be a little fed up with "code details". It's working, so no rewrite for the moment.