Nest helper functions within function that uses them