I changed the function so that it works without a helper function.