Refactor 005 to use recursion