Using a Recursive Solution to avoid mutable local variables