reworked recursive function into for loop, added quoting