Trying to make it non-recursive, should be easy. But I'm failing somewhere on the way. Not sure how and why.